package com.tjetc.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tjetc.dao.TravelPlansMapper;
import com.tjetc.entity.TravelPlans;
import com.tjetc.service.TravelPlansService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 旅游方案服务实现类
 */
@Service
public class TravelPlansServiceImpl extends ServiceImpl<TravelPlansMapper, TravelPlans> implements TravelPlansService {

    @Autowired
    private TravelPlansMapper travelPlansMapper;

    @Override
    public TravelPlans getTravelPlanById(Long planId) {
        return travelPlansMapper.findTravelPlanById(planId);
    }

    @Override
    public boolean saveTravelPlan(TravelPlans travelPlan) {
        // 设置创建时间和默认状态
        if (travelPlan.getCreatedAt() == null) {
            travelPlan.setCreatedAt(LocalDateTime.now());
        }
        if (travelPlan.getStatus() == null || travelPlan.getStatus().isEmpty()) {
            travelPlan.setStatus("generated");
        }

        return this.save(travelPlan);
    }

    @Override
    public List<TravelPlans> getAllTravelPlans() {
        return travelPlansMapper.selectAll();
    }

    @Override
    public List<TravelPlans> getTravelPlansByStatus(String status) {
        return travelPlansMapper.findTravelPlansByStatus(status);
    }

    @Override
    public List<TravelPlans> getRecentPlans(Integer limit) {
        return travelPlansMapper.findRecentPlans(limit);
    }
}